﻿#include "EditorEmptyAssetPageView.h"

#include "Widgets/TextWidget.h"
#include "Widgets/RectangleWidget.h"
#include "Widgets/Positioners/VerticalPositionerWidget.h"
#include "Widgets/Mouse/MouseWidget.h"

#include "Pages/EditorPageViewModel.h"

#include "Framework/Editor.h"
#include "Theme/EditorTheme.h"

void REditorEmptyAssetPageView::BindViewModel(TSharedObjectPtr<REditorPageViewModel> InViewModel)
{
    Super::BindViewModel(InViewModel);

    ViewModel= InViewModel;


}

void REditorEmptyAssetPageView::CreateWidget(TSharedObjectPtr<RWidget> InParent)
{
    auto Text=NewWidget<RTextWidget>(InParent);
    Text->Text=U"这是一个空白或已损坏的资产";
    Text->Anchor.HorizontalFill(InParent);
    Text->HorizontalAlignment=ETextHorizontalAlignment::Center;
    Text->Height=50;
    Text->FontSize=30;

    auto Body=NewWidget<RWidget>(InParent);
    Body->Anchor.CenterIn(InParent);
    Body->Width=500;
    Body->Height=500;

    Text->Anchor.BottomReference=Body;
    Text->Anchor.BottomReferenceEdge=EVerticalWidgetEdge::Top;
    Text->Anchor.BottomOffset=30;

    auto Spliter=NewWidget<RRectangleWidget>(Body);
    Spliter->Width=1;
    Spliter->Anchor.HorizontalCenterReference=Body;
    Spliter->Anchor.TopReference=Body;
    Spliter->Anchor.BottomReference=Body;
    Spliter->FillColor=REditor::Get()->CurrentTheme->SpliterColor;

    //left side of spliter
    //enable user to import asset
    auto ImportList=NewWidget<RVerticalPositionerWidget>(Body);
    ImportList->Spacing=10;

    ImportList->Anchor.LeftReference=Body;
    ImportList->Anchor.RightReference= Body;
    ImportList->Anchor.RightReferenceEdge=EHorizontalWidgetEdge::Center;
    ImportList->Anchor.RightOffset=10;
    ImportList->Anchor.TopReference=Body;
    ImportList->Anchor.BottomReference=Body;

    //right side of spliter
    //enable user to create new asset
    auto CreateList=NewWidget<RVerticalPositionerWidget>(Body);
    CreateList->Spacing=10;

    CreateList->Anchor.RightReference= Body;
    CreateList->Anchor.LeftReference=Body;
    CreateList->Anchor.LeftReferenceEdge=EHorizontalWidgetEdge::Center;
    CreateList->Anchor.LeftOffset=10;
    CreateList->Anchor.TopReference=Body;
    CreateList->Anchor.BottomReference=Body;

    auto ImportText=NewWidget<RTextWidget>(ImportList);
    ImportText->Text=U"导入资产";
    ImportText->Height=50;
    ImportText->FontSize=25;

    auto ImportText2=NewWidget<RTextWidget>(ImportList);
    ImportText2->Text=U"导入一张新的图片";
    ImportText2->Height=30;
    ImportText2->Color=SColor::FromHexRGB(0x0078D4);
    
    {
        auto ImportText2Mouse=NewWidget<RMouseWidget>(ImportText2);
        RTextWidgetWeakPtr ImportText2Weak=ImportText2;
        ImportText2Mouse->Width=[ImportText2Weak]()
        {
            return ImportText2Weak->GetTextSize().X;
        };

        ImportText2Mouse->Height=[ImportText2Weak]()
        {
            return ImportText2Weak->GetTextSize().Y;
        };

        ImportText2Mouse->OnClicked.BindLambda([this](const SMouseButtonEvent&)
        {
            ViewModel->ImportImage();
            return true;
        });
    }


    auto ImportText3=NewWidget<RTextWidget>(ImportList);
    ImportText3->Text=U"导入一个新的模型";
    ImportText3->Height=30;
    ImportText3->Color=SColor::FromHexRGB(0x0078D4);
    {
        auto ImportText3Mouse=NewWidget<RMouseWidget>(ImportText3);
        RTextWidgetWeakPtr ImportText3Weak=ImportText3;
        ImportText3Mouse->Width=[ImportText3Weak]()
        {
            return ImportText3Weak->GetTextSize().X;
        };

        ImportText3Mouse->Height=[ImportText3Weak]()
        {
            return ImportText3Weak->GetTextSize().Y;
        };

        ImportText3Mouse->OnClicked.BindLambda([this](const SMouseButtonEvent&)
        {
            ViewModel->ImportMesh();
            return true;
        });
    }

    auto ImportText4=NewWidget<RTextWidget>(ImportList);
    ImportText4->Text=U"导入一段音频";
    ImportText4->Height=30;
    ImportText4->Color=SColor::FromHexRGB(0x0078D4);
    {
        auto ImportText4Mouse=NewWidget<RMouseWidget>(ImportText4);
        RTextWidgetWeakPtr ImportText4Weak=ImportText4;
        ImportText4Mouse->Width=[ImportText4Weak]()
        {
            return ImportText4Weak->GetTextSize().X;
        };

        ImportText4Mouse->Height=[ImportText4Weak]()
        {
            return ImportText4Weak->GetTextSize().Y;
        };

        ImportText4Mouse->OnClicked.BindLambda([this](const SMouseButtonEvent&)
        {
            ViewModel->ImportAudio();
            return true;
        });
    }


    auto CreateText=NewWidget<RTextWidget>(CreateList);
    CreateText->Text=U"创建资产";
    CreateText->Height=50;
    CreateText->FontSize=25;

    auto CreateText2=NewWidget<RTextWidget>(CreateList);
    CreateText2->Text=U"创建一个材质";
    CreateText2->Height=30;
    CreateText2->Color=SColor::FromHexRGB(0x0078D4);
    {
        auto CreateText2Mouse=NewWidget<RMouseWidget>(CreateText2);
        RTextWidgetWeakPtr CreateText2Weak=CreateText2;
        CreateText2Mouse->Width=[CreateText2Weak]()
        {
            return CreateText2Weak->GetTextSize().X;
        };

        CreateText2Mouse->Height=[CreateText2Weak]()
        {
            return CreateText2Weak->GetTextSize().Y;
        };

        CreateText2Mouse->OnClicked.BindLambda([this](const SMouseButtonEvent&)
        {
            ViewModel->CreateMaterial();
            return true;
        });
    }

    auto CreateText3=NewWidget<RTextWidget>(CreateList);
    CreateText3->Text=U"创建一个场景";
    CreateText3->Height=30;
    CreateText3->Color=SColor::FromHexRGB(0x0078D4);
    {
        auto CreateText3Mouse=NewWidget<RMouseWidget>(CreateText3);
        RTextWidgetWeakPtr CreateText3Weak=CreateText3;
        CreateText3Mouse->Width=[CreateText3Weak]()
        {
            return CreateText3Weak->GetTextSize().X;
        };

        CreateText3Mouse->Height=[CreateText3Weak]()
        {
            return CreateText3Weak->GetTextSize().Y;
        };

        CreateText3Mouse->OnClicked.BindLambda([this](const SMouseButtonEvent&)
        {
            ViewModel->CreateScene();
            return true;
        });
    }
}
